package com.jesper.seckill.controller;

import com.jesper.seckill.entity.vo.request.PageBaseReq;
import com.jesper.seckill.entity.vo.response.PageBaseResp;
import com.jesper.seckill.entity.vo.response.ResponseData;
import com.jesper.seckill.entity.vo.response.goods.GoodsVO;
import com.jesper.seckill.service.IGoodsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;

/**
 * @author sjw
 * @since 2024-01-18
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;

    @GetMapping("/page")
    @ApiOperation("商品分页")
    public ResponseData<PageBaseResp<GoodsVO>> page(@Valid PageBaseReq request) {
        return ResponseData.ok(goodsService.pageGoods(request));
    }

    @GetMapping("/list")
    @ApiOperation("商品列表")
    public ResponseData<List<GoodsVO>> list() {
        return ResponseData.ok(goodsService.listGoods());
    }

    @GetMapping("/goodDetail/{goodsId}")
    @ApiOperation("商品详情")
    public ResponseData<GoodsVO> goodDetail(@PathVariable("goodsId") long goodsId) {
        return ResponseData.ok(goodsService.goodDetail(goodsId));
    }
}
